<template>
  <transition name="move">
    <div class="singer-detail">
      <music-list :songs="songs" :title="title" :bg-image="bgImage"></music-list>
    </div>
  </transition>
</template>

<script>
  import {mapGetters} from 'vuex'
  import {getSingerDetail} from "api/singer";
  import {ERR_OK} from "api/config";
  import {createSong} from "common/js/song";
  import MusicList from 'components/music-list/music-list'
  export default {
    name: "singer-detail",
    computed: {
      title(){
        return this.singer.name
      },
      bgImage(){
        return this.singer.avatar
      },
      ...mapGetters([
        'singer'
      ])
    },
    components:{
      MusicList
    },
    data() {
      return {
        songs: []
      }
    },
    created() {
      this._getDetail()

    },
    methods: {
      _getDetail() {
        if (!this.singer.id) {
          this.$router.push('/singer')
          return
        }
        getSingerDetail(this.singer.id).then((res) => {
          if (res.code === ERR_OK) {
            this.songs = this._handleSingerDetail(res.data.list);
            console.log(this.songs)
          }
        })
      },
      _handleSingerDetail(list) {
        let result = []
        list.forEach((item) => {
          let {musicData} = item
          if (musicData.songid && musicData.albummid) {
            result.push(createSong(musicData))
          }
        })
        return result
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import '~common/stylus/variable.styl'
  .move-enter-active, .move-leave-active
    transition all .3s

  .move-enter, .move-leave-to
    transform translate3d(100%, 0, 0)

</style>
